<template>
  <!-- 专利 -->
  <el-descriptions :column="2" size="large">
    <el-descriptions-item label-class-name="right-align" label='成果来源'>
      <span class="text--info subtext" v-if='patentInfo.projectId'>项目</span>
      <span class="text--info subtext" v-else>非项目</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='专利名称'>
      <span class="text--info subtext">{{patentInfo.patenName}}</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='所属项目' v-if='patentInfo?.projectId'>
      <span class="text--info subtext">{{projectInfo?.projectName}}</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='项目编号' v-if='patentInfo?.projectId'>
      <span class="text--info subtext">{{projectInfo.projectCode}}</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='专利申请号'>
      <span class="text--info subtext">{{patentInfo?.applyNum}}</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='专利申请日期'>
      <span class="text--info subtext">{{patentInfo?.applyDate}}</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='专利类型'>
      <span class="text--info subtext">{{model.patentTypes[patentInfo?.patentType]}}</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='专利来源'>
      <span class="text--info subtext">{{model.patentSources[patentInfo?.patentSource]}}</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='所属公司主体'>
      <span class="text--info subtext">{{patentInfo.projectLeaderName}}</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='法律状态'>
      <span class="text--info subtext">{{model.lawStatuss[patentInfo?.lawStatus]}}</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='授权号'>
      <span class="text--info subtext">{{patentInfo.authNum}}</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='授权日期'>
      <span class="text--info subtext">{{patentInfo.authDate}}</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='发明人'>
      <span class="text--info subtext" v-for="item in patentInfo.inventorList" :key="item.id">{{item.name}}&nbsp;&nbsp;</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='申请人或权利人'>
      <span class="text--info subtext" v-for="item in patentInfo.patentOwnerList" :key="item.id">{{item.name}}&nbsp;&nbsp;</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='上传文档'>
      <div v-if="patentInfo.attachmentList?.length" class="file-wrap">
        <p
          class="text--info download-link subtext"
          v-for="(obj, index) in patentInfo?.attachmentList"
          :key="index"
          @click.prevent="handlePreview(obj)"
        >
          <el-link :underline="false" icon="el-icon-folder">{{ obj?.fileName }}&nbsp;&nbsp;</el-link>
        </p>
      </div>
      <div class="text--info subtext file-wrap" v-else> - </div>
    </el-descriptions-item>
  </el-descriptions>
</template>

<script lang="ts" setup>
import {ref, watch,reactive} from "vue";
import { getPatentById } from "/@/api/document";
const props = defineProps({
  projectInfo: {
    type: Object,
    default:()=>{}
  },
});
let info = ref({});
let patentInfo = ref({})
let model = reactive({
  patentTypes: {
    1: "发明专利" ,
    2: "实用新型专利",
    3: "外观设计专利"
  },
  lawStatuss: {
    1: "申请中",
    2: "无效",
    3: "有效"
  },
  patentSources: {
    1: "首次申请",
    2: "基于优先权的申请",
    3: "基于母案的分案申请",
    4: "外部购买",
    5: "内部转让"
  },
})

const getData = async id => {
  const { data,code } = await getPatentById(id);
  if(code == 200){
    patentInfo.value = data;
    patentInfo.value.inventorList = JSON.parse(data.inventor);
    patentInfo.value.patentOwnerList = JSON.parse(data.patentOwner);
    patentInfo.value.attachmentList = JSON.parse(data.attachment);
  }
};

const handlePreview = (item: any) => {
  if (item.response) {
    window.open(
      `${location.origin}${location.pathname}#/online?uuidFile=${item?.response.data.uuidFile}&fileName=${item?.response.data.fileName}`
    );
  } else {
    window.open(
      `${location.origin}${location.pathname}#/online?uuidFile=${item.uuidFile}&fileName=${item.fileName}`
    );
  }
};

watch(
  () => props.projectInfo,
  newvalue => {
    info.value = newvalue;
    const kyId = newvalue.kyId
    if(kyId){
      getData(kyId)
    }
  },
  { immediate: true }
);
</script>

<style lang="scss" scoped>
  .file-wrap{
    display: inline-block;
    vertical-align: top
  }
</style>
